/////////////////////////////////////////////////////////////////////////////
// Defines interfaces for critical section functions.
//
// Version 1.0 - 15 june 2007
//
// Copyright (c) 2007 by FlexByte Software (http://flexbyte.com)
// All rights reserved.
//
// You may use the source code in any product (freeware, commercial, etc.). 
// You may modify the source code as you want except 
// you cannot modify the copyright details at the top of each module.
// If you have a web site or blog give a link to our web site, flexbyte.com
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CFlexLock
/////////////////////////////////////////////////////////////////////////////
#ifndef FlexLock_H
#define FlexLock_H
class CFlexLock
{
public:
// Constructor/Destructor
	CFlexLock()
	{
		::InitializeCriticalSection( &m_lock );
	}

	~CFlexLock()
	{
		::DeleteCriticalSection( &m_lock );
	}

// Implementation
	virtual void Lock()
	{
		::EnterCriticalSection( &m_lock );
	}

	virtual void Unlock()
	{
		::LeaveCriticalSection( &m_lock );
	}

private:
	CRITICAL_SECTION	m_lock;
};
/////////////////////////////////////////////////////////////////////////////
// CFlexAutoLock
/////////////////////////////////////////////////////////////////////////////
class CFlexAutoLock
{
public:
// Constructor/Destructor
	CFlexAutoLock(CFlexLock * lock)
		: m_lock( lock )
	{
		m_lock->Lock();
	}

	~CFlexAutoLock()
	{
		m_lock->Unlock();
	}

private:
	CFlexLock *	m_lock;
};
/////////////////////////////////////////////////////////////////////////////
#endif
